/*
* @Author: Josh
* @Date:   2019-01-24 11:27:28
* @Last Modified by:   Administrator
* @Last Modified time: 2019-04-11 19:17:35
*/
'use strict';

require('./index.css');
var _mall = require('util/mall.js');

// 带搜索框的通用页面头部
var header   = {
    init          : function(){
        this.onLoad();
        this.bindEvent();
    },
    onLoad : function(){
        var keyword = _mall.getUrlParam('keyword');
        //若输入框有值则回填输入框
        if(keyword){
            $('#search-input').val(keyword);
        };
    },
    bindEvent : function(){
        var _this = this;
        //搜索按钮点击后做搜索提交
        $('#search-btn').click(function(){
            _this.searchSubmit();
        });
        //输入回车后，做搜索提交
         $('#search-input').keyup(function(e){
            //13为回车键
            if(e.keyCode === 13){
                 _this.searchSubmit();
            }
         });
    },
    //搜索的提交
    searchSubmit : function(){
        var keyword = $.trim($('#search-input').val());
        //如果搜索框有值
        if(keyword){
            //跳转到list页面
            window.location.href = './list.html?keyword=' + keyword;
        }
        else{
            //返回首页
            _mall.goHome();
        }
    }

};

header.init();